﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using System.IO;

namespace WebApplication1
{
    public partial class GetImage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           // Check for the query string parameter. 4: 
            string id = Request.QueryString["ID"];
            if (!string.IsNullOrWhiteSpace(id))
            {

                Business.Food fd= new Business.Food();
                byte[] imageBinary= fd.GetImageBinary(Convert.ToInt64(id));
               // byte[] convertedImage = Common.convertImageSize(imageBinary);
                // Add a default image if it is empty
                if (imageBinary == null || imageBinary.Length == 0)
                {
                    imageBinary = File.ReadAllBytes(Server.MapPath("~/images")+ "/empty.jpg");



                }
                
                Response.Clear();
                Response.ContentType = "image/jpeg";
                bool forDownload = false;
                if (forDownload)
                {
                    Response.AppendHeader("content-disposition", "attachment; filename=sample.jpg");
                }
                Response.BinaryWrite(imageBinary);
                Response.End();
            }
             
        }
    }
}